package com.auth.web.result;

import lombok.Data;

/**
 * @author: 王霄
 * @date: 2021/9/6 20:31
 */
@Data
public class R<T> {

    private int code;
    private String message;
    private T data;

    private R(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> R<T> ok(T data) {
        return new R<>(RCode.SUCCESS.getCode(), RCode.SUCCESS.getMsg(), data);
    }

    public static <T> R<T> ok() {
        return ok(null);
    }

    public static <T> R<T> fail(T data) {
        return new R<>(RCode.FALL.getCode(), RCode.FALL.getMsg(), data);
    }

    public static <T> R<T> fail() {
        return new R<>(RCode.FALL.getCode(), RCode.FALL.getMsg(), null);
    }

    public static <T> R<T> fail(RCode resultEnum, T data) {
        return new R<>(resultEnum.getCode(), resultEnum.getMsg(), data);
    }

    public static <T> R<T> fail(RCode resultEnum) {
        return new R<>(resultEnum.getCode(), resultEnum.getMsg(), null);
    }

}
